from django.db import models


class Student(models.Model):
    """学生"""
    name = models.CharField(verbose_name='姓名', max_length=24)
    gender = models.CharField(verbose_name='性别', max_length=6)
    age = models.IntegerField(verbose_name='年龄')
    birthday = models.DateField(verbose_name="出生日期")
    # 班级
    school_class = models.ForeignKey(verbose_name="班级", to='SchoolClass', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '学生'
        verbose_name_plural = verbose_name


class School(models.Model):
    """学校"""
    name = models.CharField(verbose_name="校名", max_length=128)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "学校"
        verbose_name_plural = verbose_name


class SchoolClass(models.Model):
    """学校班级"""
    name = models.CharField(verbose_name="班级名称", max_length=76)
    grade_num = models.IntegerField(verbose_name="年级编号")
    class_num = models.IntegerField(verbose_name="班级编号")
    # 学校
    school = models.ForeignKey(verbose_name="学校", to='School', on_delete=models.CASCADE)

    def get_class_name(self):
        num_dict = {
            1: "一",
            2: "二",
            3: "三",
            5: "五",
            6: "六",
        }
        """
        获取班级名称
        :return: 班级名称: 比如 一年级(2)班
        """
        return "{}年级({})班".format(num_dict.get(self.grade_num), self.class_num)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "班级"
        verbose_name_plural = verbose_name
